﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Write.API.Applications.Login;
using MediatR;

namespace MangoMes.Write.API.Applications.Transfer
{
    public class TransferCreateHandler : IRequestHandler<TransferCreateCommod, ResultsDTO>
    {

        private readonly IBateRepository<TransferTable> TransferTable;
        private readonly IBateRepository<Logincommonality> _Logincommonality;

        public TransferCreateHandler(IBateRepository<TransferTable> transferTable, IBateRepository<Logincommonality> logincommonality)
        {
            TransferTable = transferTable;
            _Logincommonality = logincommonality;
        }

        public async Task<ResultsDTO> Handle(TransferCreateCommod request, CancellationToken cancellationToken)
        {
            try
            {
                var list = new ResultsDTO() { Code = 0 };

                var str = "insert transfertable values(@Transferid,@TransferOrderNumber,@TransferOrderName,@isType,@StashId,@StashIds,@infoMess,@Transfertime)";

                var newdata = new TransferTable()
                {
                    Transferid = 0,
                    StashId = request.StashId,
                    StashIds = request.StashIds,
                    infoMess=request.infoMess,
                    isType=request.isType, 
                    TransferOrderName=request.TransferOrderName,
                    TransferOrderNumber=request.TransferOrderNumber,
                    Transfertime=request.Transfertime,
                };

                DapperHelper dapperHelper = new DapperHelper();
                var ctrdata = await TransferTable.Add(str, newdata, dapperHelper.RBACWrite);


                if (ctrdata != null)
                {
                    list.Code = 1;
                    list.Message = "转移挑拨单添加成功";
                }

                return list;
            }
            catch (Exception)
            {

                throw;
            }
           

        }
    }
}
